<!DOCTYPE html>
<html lang="en">
	<head> 
		<meta charset="UTF-8"> 
		<meta http-equiv="X-UA-Compatible" content="IE=edge">   
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>game</title>
		<style type="text/css">
			body {
				background-color: black; //设置背景颜色
			}

			.img {
				position: absolute;
				left: 10px;
				top: 100px
			}
		</style>
	</head>
	<body>

		<img src="image/player_right.gif" class="img" />
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
		<script>
			function Change() {
				$("img").dblclick(function() { //双击变身,dblclick双击
					$("img").attr("src", "image/player2.gif"); //一个参数获取，两个参数设置

					$("img").dblclick(function() { //再双击还原
						$("img").attr("src", "player_right.gif");
					})
				})
			}
			//219971343张燚
			//禁止使用右键
			$(document).on("contextmenu", function(e) {
				e.preventDefault();
			});
			//switch实现
			function move() {
				$(window).keydown(function(e) { //键盘按下的事件，用e来接收
					let top = parseInt($("img").css("top")); //将字符串解析成整数
					let left = parseInt($("img").css("left"));
					switch (e.keyCode) { //用于获取代表键盘上的键的数字
						case 87:
							$("img").css("top", top - 50);
							break;
						case 83:
							$("img").css("top", top + 50);
							break;
						case 65:
							$("img").attr("src", "image/playerbig_left.gif");
							$("img").css("left", left - 50);
							break;
						case 68:
							$("img").attr("src", "image/playerbig_right.gif");
							$("img").css("left", left + 50);
							break;
						default:
							break;
					}
				})
			}

			$(function() {
				Change();
				move();
			})
		</script>
	</body>
</html>
